package org.threebitsoftware.tbb.module.map;

import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;

/**
 * T2Browser is created to provide and visual display of direction from the 
 * user's address to the selected contact's address and 
 */
public class T2Browser implements MapBrowserInterface {

	private String url;
	protected Shell shlT2browser;
	
	/**
	 * Default Constructor
	 */
	public T2Browser() {

	}
		
	/**
	 * Open the browser window
	 */
	public void open() {
		Display display = Display.getDefault();
		createContents();
		shlT2browser.open();
		shlT2browser.layout();
		shlT2browser.setMaximized(true);
		while (!shlT2browser.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}
	}

	/**
	 * Set the formated url for browser to launch and display it in Google maps
	 * @param url
	 */
	public void setUrl(String url) {
		this.url = url;
	}

	
	/**
	 * Create contents of the window.
	 */
	protected void createContents() {
		shlT2browser = new Shell();
		shlT2browser.setSize(1098, 793);
		shlT2browser.setText("Direction to Contact");
		shlT2browser.setLayout(null);
		
		Browser browser = new Browser(shlT2browser, SWT.NONE);
		browser.setUrl(url);
		browser.setBounds(0, 0, 1680, 1003);
	}
}
